import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        // 从session中获取token，没有则为空
        Authorization: JSON.parse(sessionStorage.getItem('Authorization')) ? JSON.parse(sessionStorage.getItem('Authorization')) : '',
        userData: null,
        loginId: sessionStorage.getItem('loginId'),
        loginAccount: sessionStorage.getItem('loginAccount'),
        loginPassword: sessionStorage.getItem('loginPassword'),
        userPar: null,
        loginPar: sessionStorage.getItem('loginPar')
    },
    mutations: {
        // 修改token(该消息来自登录页面）
        changeToken(state, token) {
            state.Authorization = token;
            sessionStorage.setItem('Authorization', token)
        },
        getUserData(state, userData) {
            state.userData = userData
        },
        getUserPar(state, userPar) {
            state.userPar = userPar
        }
    },
    actions: {
        getUserData(ctx, userData) {
            ctx.commit('getUserData', userData)
        },
        getUserPar(ctx, userPar) {
            ctx.commit('getUserPar', userPar)
        }
    },
    modules: {}
})